<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>学生管理--我的试卷</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <link rel="stylesheet" href="assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="assets/css/amazeui.datatables.min.css" />
    <link rel="stylesheet" href="assets/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/css/app.css">
    <link rel="stylesheet" href="assets/css/gb_my.css">
    <link rel="stylesheet" href="assets/css/font-awesome.css">
    <link rel="stylesheet" href="assets/css/bootstrap-reset.css">
    <link rel="stylesheet" href="assets/css/easydropdown.css">
    <link rel="stylesheet" href="assets/css/build2.css">
    <link rel="stylesheet" href="assets/css/layer-animate.css">
</head>
<body data-type="chart">
<div class="am-g tpl-g">
    <!--头部-->
    <nav class="navbar navbar-default top-navbar">
        <div class="navbar-header">
            <a class="navbar-brand waves-effect waves-dark" href="javascript:;">
                <img src="assets/img/logo.png" alt="">
                <strong>轻课网考试系统</strong>
            </a>
            <div id="sideNav" href="">
                <i class="mulv QK QK-mulu"></i>
            </div>
        </div>
        <ul class="nav navbar-top-links navbar-right aaa">
            <li>
                <a id="down_" class="sign-out dropdown-button waves-effect waves-dark" href="javascript:;">
                    <span class="am-icon-sign-out"></span> 退出
                </a>
            </li>
            <li>
                <a class="dropdown-button waves-effect waves-dark" href="javascript:;"><b>欢迎你, <span class="userName"></span> </b></a>
            </li>
        </ul>
    </nav>
    <!--导航栏-->
    <nav class="navbar-default navbar-side">
        <div class="sidebar-collapse">
            <!--用户头像-->
            <div class="tpl-sidebar-user-panel">
                <div class="tpl-user-panel-slide-toggleable">
                    <div class="tpl-user-panel-profile-picture">
                        <img src="assets/img/user04.png" alt="">
                    </div>
                </div>
            </div>
            <dl class="list_dl">
                <dt class="list_dt">
                    <a href="index.html">
                        <span class="QK1 start_before"></span>
                        <p>学生平台</p>
                    </a>
                </dt>
                <dt class="list_dt">
                    <span class="QK1 topic_before"></span>
                    <p>我的考试</p>
                    <i class="QK1 list_dt_icon"></i>
                </dt>
                <dd class="list_dd">
                    <ul>
                        <li class="list_li">
                            <a href="student.html">我的试卷</a>
                        </li>
                        <li class="list_li">
                            <a href="examRecords.html">考试记录</a>
                        </li>
                    </ul>
                </dd>
                <dt id="open" class="list_dt">
                    <span class="QK1 paper_before"></span>
                    <p>自我检测</p>
                    <i class="QK1 list_dt_icon"></i>
                </dt>
                <dd class="list_dd" style="display: block">
                    <ul>
                        <li class="list_li" id="style_li_a">
                            <a href="testing.html">自我检测</a>
                        </li>
                        <li class="list_li">
                            <a href="error.html">检测结果</a>
                        </li>
                    </ul>
                </dd>
                <dt class="list_dt">
                    <span class="QK1 user_before"></span>
                    <p>个人管理</p>
                    <i class="QK1 list_dt_icon"></i>
                </dt>
                <dd class="list_dd">
                    <ul>
                        <li class="list_li">
                            <a href="personalData.html">个人资料</a>
                        </li>
                        <li class="list_li">
                            <a href="collection.html">题目收藏</a>
                        </li>
                    </ul>
                </dd>
                <dt class="list_dt">
                    <span class="QK1 chat_before"></span>
                    <p>聊天室</p>
                    <i class="QK1 list_dt_icon"></i>
                </dt>
                <dd class="list_dd">
                    <ul>
                        <li class="list_li">
                            <a href="chatroom.html">聊天室</a>
                        </li>
                    </ul>
                </dd>
            </dl>
        </div>
    </nav>
    <!-- 内容区域 -->
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <section class="panel">
                    <header class="panel-heading">
                        <span class="label label-primary">开始做题</span>
                        <button type="button" class="btn btn-success btn-sm add_clazz btn_my" id="back">
                            <span class="QK1 QK-fanhui1"></span>&nbsp;&nbsp;返回
                        </button>
                        <div class="loading" id="header_loading">
                            <span></span>
                            <span></span>
                            <span></span>
                            <span></span>
                            <span></span>
                        </div>
                    </header>
                    <div class="panel-body">
                        <div id="unseen" class="unseen">
                            <div class="paper_all">

                            </div>
                            <div class="user_all">

                            </div>
                            <div id="test_questions">
                                <div class="test_questions_select">
                                    <div class="questions_item_radio">
                                        <h1>单选题</h1>
                                    </div>
                                    <div class="questions_item_check">
                                        <h1>多选题</h1>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-lg-1 col-sm-1">
                                <button type="button" class="btn btn-block submit_button btn_submit" id="btnSubmit">提交</button>
                            </div>
                        </div>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/theme.js"></script>
<script src="assets/js/easydropdown.js"></script>
<script src="assets/js/html5sv.js"></script>
<script type="text/javascript" src="assets/js/jquery.cookie.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/amazeui.datatables.min.js"></script>
<script src="assets/js/dataTables.responsive.min.js"></script>
<script src="assets/js/student.js"></script>
<script src="assets/js/method.js"></script>
<script>
    $('.loading').css('display' , 'inline-block');
    $(document).ready(function () {
        var storage = window.localStorage;
        var user_id = storage["uid"];
        var class_id = storage["class_id"];
        var user_name = storage["user_name"];
        //题型id
        var select_question_id = window.location.search.split("=")[1].split('&')[0];
        var question_type = window.location.search.split("=")[2].split('&')[0];
        var difficulty_questions = window.location.search.split("=")[3].split('&')[0];
        var difficulty_questions_number = window.location.search.split("=")[3].split('practiceCount')[1];
        question_type = question_type.split(",");
        difficulty_questions = difficulty_questions.split(",");
        difficulty_questions_number = difficulty_questions_number.split(",");
//        console.log(select_question_id);
//        console.log(question_type);
//        console.log(difficulty_questions);
//        console.log(difficulty_questions_number);
        var test_id_array = [],
            correct_answer_array = [],
            paper_name,
            qtype = [];
        //获取试卷
        $.ajax({
            url: localApi + "/QuestionWithBLOBs/selectByQtypeAndqlevel",
            type: 'get',
            data: {
                apikey: '1',
                dbid:select_question_id,
                qtype:question_type,
                qlevel:difficulty_questions,
                practiceCount:difficulty_questions_number
            },
            success: function(result) {
//                console.log(result.data);
                $('.loading').css('display' , 'none');
                var  m = 1,
                    i = 0,
                    a = 0,
                    b = 0;
                $.each(result.data, function(n, item) {
                    qtype.push(item.qtype);
                    test_id_array.push(item.id);
                    correct_answer_array.push(item.skey);
                    var content_s = item.content;
                    var content_ss = content_s.replace(/<[^>]+>/g, ""); //去除html标签
                    var content_sss = content_ss.replace('&nbsp;', "");
                    if(item.qtype == 1){
                        var radio_array = '<div class="radio_every">\n' +
                            '            <p class="subject_radio">'+ m +'&nbsp;.(单选)&nbsp;'+ content_sss +'</p>\n' +
                            //                            '            <span class="span_add"></span>\n'+
                            '            <div class="row'+ m +'">\n' +
                            '            </div>\n' +
                            '        </div>';
                        $('.questions_item_radio').append(radio_array);
                        $.each(item.questionOptions.reverse(), function(o, qop1) {
                            if(qop1.salisa == 'A') {
                                var coulmn = '<div id="select'+ i +'all'+ qop1.salisa +'" class="radio col-lg-12">\n' +
                                    '              <input type="radio" name="radio'+ m +'" id="radio'+ i +'" value="option1">\n' +
                                    '              <label for="radio'+ i +'">'+  qop1.salisa + ".&nbsp;" + qop1.soption  +'</label>\n' +
                                    '         </div>';
                                $(".row" + m).append(coulmn);
                                i++;
                            }
                        });
                        $.each(item.questionOptions.reverse(), function(o, qop1) {
                            if(qop1.salisa == 'B') {
                                var coulmn = '<div id="select'+ i +'all'+ qop1.salisa +'" class="radio col-lg-12">\n' +
                                    '                    <input type="radio" name="radio'+ m +'" id="radio'+ i +'" value="option2">\n' +
                                    '                    <label for="radio'+ i +'">'+  qop1.salisa + ".&nbsp;" + qop1.soption  +'</label>\n' +
                                    '                </div>';
                                $(".row" + m).append(coulmn);
                                i++;
                            }

                        });
                        $.each(item.questionOptions.reverse(), function(o, qop1) {
                            if(qop1.salisa == 'C') {
                                var coulmn = '<div id="select'+ i +'all'+ qop1.salisa +'" class="radio col-lg-12">\n' +
                                    '                    <input type="radio" name="radio'+ m +'" id="radio'+ i +'" value="option3">\n' +
                                    '                    <label for="radio'+ i +'">'+  qop1.salisa + ".&nbsp;" + qop1.soption  +'</label>\n' +
                                    '                </div>';
                                $(".row" + m).append(coulmn);
                                i++;
                            }
                        });
                        $.each(item.questionOptions.reverse(), function(o, qop1) {
                            if(qop1.salisa == 'D') {
                                var coulmn = '<div id="select'+ i +'all'+ qop1.salisa +'" class="radio col-lg-12">\n' +
                                    '                    <input type="radio" name="radio'+ m +'" id="radio'+ i +'" value="option4">\n' +
                                    '                    <label for="radio'+ i +'">'+  qop1.salisa + ".&nbsp;" + qop1.soption  +'</label>\n' +
                                    '                </div>';
                                $(".row" + m).append(coulmn);
                                i++;
                            }
                        });
                        $('.questions_item_radio').append(radio_array);
                        var odd_p = $('.questions_item_radio .radio_every:nth-child(odd)').find('p');
                        $("<div class='last_p'>&nbsp;</div>").replaceAll(odd_p);
                        m++;
                        a++;
                    }
                    if(item.qtype == 2){
                        var checked_array = '<div class="checkbox_every">\n' +
                            '            <p class="subject_checked">'+ m +'&nbsp;.(多选)&nbsp;'+ content_sss +'</p>\n' +
                            '            <div class="row'+ m +'">\n' +
                            '            </div>\n' +
                            '        </div>';
                        $('.questions_item_check').append(checked_array);
                        $.each(item.questionOptions.reverse(), function(t, qop1) {
                            if(qop1.salisa == 'A') {
                                var coulmn = '<div id="select'+ i +'all'+ qop1.salisa +'" class="checkbox col-md-12">\n' +
                                    '             <input id="checkbox'+ i +'" class="styled" type="checkbox">\n' +
                                    '             <label for="checkbox'+ i +'">'+  qop1.salisa + ".&nbsp;" + qop1.soption  +'</label>\n' +
                                    '         </div>';
                                $(".row" + m).append(coulmn);
                                i++;
                            }
                        });
                        $.each(item.questionOptions.reverse(), function(t, qop1) {
                            if(qop1.salisa == 'B') {
                                var coulmn = '<div id="select'+ i +'all'+ qop1.salisa +'" class="checkbox col-md-12">\n' +
                                    '                        <input id="checkbox'+ i +'" class="styled" type="checkbox">\n' +
                                    '             <label for="checkbox'+ i +'">'+  qop1.salisa + ".&nbsp;" + qop1.soption  +'</label>\n' +
                                    '                    </div>';
                                $(".row" + m).append(coulmn);
                                i++;
                            }

                        });
                        $.each(item.questionOptions.reverse(), function(t, qop1) {
                            if(qop1.salisa == 'C') {
                                var coulmn = '<div id="select'+ i +'all'+ qop1.salisa +'" class="checkbox col-md-12">\n' +
                                    '                        <input id="checkbox'+ i +'" class="styled" type="checkbox">\n' +
                                    '             <label for="checkbox'+ i +'">'+  qop1.salisa + ".&nbsp;" + qop1.soption  +'</label>\n' +
                                    '                    </div>';
                                $(".row" + m).append(coulmn);
                                i++;
                            }
                        });
                        $.each(item.questionOptions.reverse(), function(t, qop1) {
                            if(qop1.salisa == 'D') {
                                var coulmn = '<div id="select'+ i +'all'+ qop1.salisa +'" class="checkbox col-md-12">\n' +
                                    '                        <input id="checkbox'+ i +'" class="styled" type="checkbox">\n' +
                                    '             <label for="checkbox'+ i +'">'+  qop1.salisa + ".&nbsp;" + qop1.soption  +'</label>\n' +
                                    '                    </div>';
                                $(".row" + m).append(coulmn);
                                i++;
                            }
                        });
                        $.each(item.questionOptions.reverse(), function(t, qop1) {
                            if(qop1.salisa == 'E') {
                                var coulmn = '<div id="select'+ i +'all'+ qop1.salisa +'" class="checkbox col-md-12">\n' +
                                    '                        <input id="checkbox'+ i +'" class="styled" type="checkbox">\n' +
                                    '             <label for="checkbox'+ i +'">'+  qop1.salisa + ".&nbsp;" + qop1.soption  +'</label>\n' +
                                    '                    </div>';
                                $(".row" + m).append(coulmn);
                                i++;
                            }
                        });
                        $.each(item.questionOptions.reverse(), function(t, qop1) {
                            if(qop1.salisa == 'F') {
                                var coulmn = '<div id="select'+ i +'all'+ qop1.salisa +'" class="checkbox col-md-12">\n' +
                                    '                        <input id="checkbox'+ i +'" class="styled" type="checkbox">\n' +
                                    '             <label for="checkbox'+ i +'">'+  qop1.salisa + ".&nbsp;" + qop1.soption  +'</label>\n' +
                                    '                    </div>';
                                $(".row" + m).append(coulmn);
                                i++;
                            }
                        });
                        $.each(item.questionOptions.reverse(), function(t, qop1) {
                            if(qop1.salisa == 'G') {
                                var coulmn = '<div id="select'+ i +'all'+ qop1.salisa +'" class="checkbox col-md-12">\n' +
                                    '                        <input id="checkbox'+ i +'" class="styled" type="checkbox">\n' +
                                    '             <label for="checkbox'+ i +'">'+  qop1.salisa + ".&nbsp;" + qop1.soption  +'</label>\n' +
                                    '                    </div>';
                                $(".row" + m).append(coulmn);
                                i++;
                            }
                        });
                        $.each(item.questionOptions.reverse(), function(t, qop1) {
                            if(qop1.salisa == 'H') {
                                var coulmn = '<div id="select'+ i +'all'+ qop1.salisa +'" class="checkbox col-md-12">\n' +
                                    '                        <input id="checkbox'+ i +'" class="styled" type="checkbox">\n' +
                                    '             <label for="checkbox'+ i +'">'+  qop1.salisa + ".&nbsp;" + qop1.soption  +'</label>\n' +
                                    '                    </div>';
                                $(".row" + m).append(coulmn);
                                i++;
                            }
                        });
//                        $('.row' + m).children(':last-child').css('margin-bottom' , '1.5rem');
                        $('.questions_item_check').append(checked_array);
                        var odd_p = $('.questions_item_check .checkbox_every:nth-child(odd)').find('p');
                        $("<div class='last_p'>&nbsp;</div>").replaceAll(odd_p);
                        m++;
                        b++;
                    }
                });
                var qtype_string = qtype.join("");
                if(qtype_string.indexOf('1') == -1){
                    $('.questions_item_radio').remove();
                }
                if(qtype_string.indexOf('2') == -1){
                    $('.questions_item_check').remove();
                }
                //请求题库类型
                $.ajax({
                    url: localApi + "/QuestionDb/all",
                    type: 'get',
                    async:false,
                    data: {
                        apikey: '1',
                    },
                    success: function(result) {
//                        console.log(result.data);
                        $.each(result.data , function (t , titem) {
                            if(titem.id == select_question_id){
                                paper_name = titem.dname;
                                var title_information = '<h1>试卷名称</h1>\n' +
                                    '                                <h2>试卷信息</h2>\n' +
                                    '                                <div class="paper_infromation">\n' +
                                    '                                    <p>\n' +
                                    '                                        <span>\n' +
                                    '                                            <strong>试题类型</strong>\n' +
                                    '                                            <span>'+ titem.dname +'</span>\n' +
                                    '                                        </span>\n' +
                                    '                                    </p>\n' +
                                    '                                    <p>\n' +
                                    '                                        <span>\n' +
                                    '                                            <strong>单选题:</strong>\n' +
                                    '                                            <span>'+ a +'道</span>\n' +
                                    '                                        </span>\n' +
                                    '                                        <span>\n' +
                                    '                                            <strong>多选题:</strong>\n' +
                                    '                                            <span>'+ b +'道</span>\n' +
                                    '                                        </span>\n' +
                                    '                                    </p>\n' +
                                    '                                </div>';
                                $('.paper_all').append(title_information);
                            }
                        })
                    }
                });
                var user_all = '<h2>考生信息</h2>\n' +
                    '                                <div class="paper_infromation">\n' +
                    '                                    <p>\n' +
                    '                                        <span>\n' +
                    '                                            <strong>姓名:</strong>\n' +
                    '                                            <span>'+ user_name +'</span>\n' +
                    '                                        </span>\n' +
                    '                                    </p>\n' +
                    '                                </div>';
                $('.user_all').append(user_all);
//                console.log(paper_name);
                var userAnswer_radio = [],
                    userAnswer_checked = [],
                    short_answer_array = [];
                //提交数据
                $('#btnSubmit').click(function () {
                    //读取选择的选项
                    var parent_select_radio = $('.questions_item_radio').children().children().children().find('input:checked');
                    $.each(parent_select_radio.parent().parent() , function (n , item) {
                        var answers_check_radio = "";
                        $.each($(this).find('input:checked').parent() , function (a , aitem) {
                            answers_check_radio= answers_check_radio + $(this).attr('id').split('all')[1];
                        });
                        userAnswer_radio.push(answers_check_radio);
                    });
                    var parent_select_check = $('.questions_item_check').children().children().children().find('input:checked');
                    $.each(parent_select_check.parent().parent() , function (n , item) {
                        var answers_check_check = "";
                        $.each($(this).find('input:checked').parent() , function (a , aitem) {
                            answers_check_check= answers_check_check + $(this).attr('id').split('all')[1];
                        });
                        userAnswer_checked.push(answers_check_check);
                    });
                    short_answer_array = $.merge(userAnswer_radio , userAnswer_checked);
//            console.log(short_answer_array);
                    //判断试题的正误并添加在数组中
                    function checkAnswers() {
                        var resultArr = [],
                            flag = false;
                        for (i = 0; i < correct_answer_array.length; i++) {
                            if(correct_answer_array[i] == short_answer_array[i]) {
                                flag = true;
                            } else {
                                flag = false;
                            }
                            resultArr.push(flag);
                        }
                        return resultArr;
                    }
                    var results = checkAnswers();
                    var y = [];
                    for(var x = 0;x < results.length;x++){
                        if(results[x] == true){
                            y.push(x);
                        }
                    }
                    var true_number = y.length;
//            console.log(true_number);
//            console.log(test_id_array);
//            console.log(results);
//            console.log(short_answer_array);
                    var user_questions_number = test_id_array.length;
//            console.log(user_questions_number);
                    if(results.length < test_id_array.length || short_answer_array.length < test_id_array.length){
                        var obj={
                            type:"slideFromBottom",
                            confirm:"true",
                            content:"<div>请将试题填写完毕!!!",
                            btn:["","可以"]
                        };
                        method.msg_layer(obj);
                        results.splice(0,results.length);
                        short_answer_array.splice(0,short_answer_array.length);
                    }else{
                        $.ajax({
                            "type":'post',
                            url: localApi + "/PracticeRecord/add",
                            async:false,
                            data: {
                                apikey: '1',
                                uid: user_id,
                                questionNumber:user_questions_number,
                                trueNumber:true_number,
                                dbName:paper_name,
                                qid:test_id_array,
                                istrue:results,
                                userAnswer:short_answer_array
                            },
                            success:function (result) {
                                console.log('提交成功');
                                var obj={
                                    type:"slideFromBottom",
                                    confirm:"true",
                                    content:"<div>提交成功",
                                    btn:["","完成"]
                                };
                                method.msg_layer(obj);
                                $('.layer-commit').click(function () {
                                    window.location.href = 'testing.html';
                                });
                            },
                            error:function (){
                                console.log('失败了');
                                var obj={
                                    type:"layerFadeIn",
                                    close:"true",
                                    content:"<div>提交失败",
                                    btn:["取消",""]
                                };
                                method.msg_layer(obj);
                                $('.layer-commit').remove();
                            }
                        });
                    }
                });
            }
        });
    });
</script>
<script>
    $(document).ready(function() {
        $('#back').click(function () {
            window.location.href = "testing.html";
        });
        $(".list_dt").on("click", function() {
            $('.list_dd').stop();
            $(this).siblings("dt").removeAttr("id");
            if($(this).attr("id") == "open") {
                $(this).removeAttr("id").siblings("dd").slideUp();
            } else {
                $(this).attr("id", "open").next().slideDown().siblings("dd").slideUp();
            }
        });
    });
</script>
<script>
    $(document).ready(function() {
        $(".dropdown-button").dropdown();
        $("#sideNav").click(function() {
            if($(this).hasClass('closed')) {
                $('.navbar-side').animate({
                    left: '0px'
                });
                $(this).removeClass('closed');
                $('#page-wrapper').animate({
                    'margin-left': '260px'
                });
            } else {
                $(this).addClass('closed');
                $('.navbar-side').animate({
                    left: '-260px'
                });
                $('#page-wrapper').animate({
                    'margin-left': '0px'
                });
            }
        });
    });
    $(".dropdown-button").dropdown();
</script>